import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        InitClass initClass = new InitClass();
        HashMap<String, Host> hosts = initClass.hosts;
        ArrayList<Exchange> exchanges = initClass.exchanges;
        Scanner input = new Scanner(System.in);
        System.out.println("请输入网桥个数");
        int eNum = input.nextInt();
        System.out.println("请输入每个网桥的主机个数");
        int hostNum = input.nextInt();

        //初始化
        initClass.init(eNum,hostNum);
        //帧结构 源地址 目的地址 数据
        String frame1 = "e2h2 e0h2 111";
        String frame2 = "e0h2 e2h1 222";
        String frame3 = "e2h2 e0h1 333";
        String frame4 = "e2h1 e0h2 444";
        String frame5 = "e0h2 e2h1 444";

        ArrayList<String> strs = new ArrayList<>();
        strs.add(frame1);
        strs.add(frame2);
        strs.add(frame3);
        strs.add(frame4);
        strs.add(frame5);

        for (String frame : strs) {
            String[] s = frame.split(" ");
            String srcMac = s[0];
            Host host = hosts.get(srcMac);
            System.out.println("源地址:"+srcMac+"的主机开始传输帧");
            //从源地址对应的主机开始传输帧
            host.transferFrame(null,frame);
        }

        //打印交换表
        for (Exchange exchange1 : exchanges) {
            Map<String, String[]> exchangeTable = exchange1.exchangeTable;
            System.out.println("交换机"+exchange1.getName()+"地址表：");
            for (String s1 : exchangeTable.keySet()) {
                String[] ss = exchangeTable.get(s1);
                System.out.println("地址："+s1+",端口："+ss[0]+",更新时间："+ss[1]);
            }
        }
    }
}
